<template>
  <div style="position: relative; height: 100%">
    <el-button size="small" icon="iconfont icon-fabuxinwen" class="commonBtn biddBtn" @click="publishBtn"
      >发布招标书</el-button
    >
    <el-tabs class="sbTabs" v-model.trim="biddTypeValue" @tab-click="handleClick">
      <el-tab-pane v-for="(item, index) in biddTypes" :key="index" :label="item.label" :name="item.value">
      </el-tab-pane>
    </el-tabs>
    <div class="list-container">
      <un-publish-table ref="tablelist" @openBidd="openBiddVisible" v-if="biddTypeValue === '1'"> </un-publish-table>
      <publishing-table v-else-if="biddTypeValue === '2'"></publishing-table>
      <shortlist-table v-else-if="biddTypeValue === '3'"></shortlist-table>
      <winning-bid-table v-else-if="biddTypeValue === '4'"></winning-bid-table>
      <flow-mark-table ref="tablelist" v-else-if="biddTypeValue === '5'" @goTender="reTender"></flow-mark-table>
    </div>
    <el-dialog
      width="1200px"
      :center="true"
      title="查看未发布招标书"
      :before-close="closeDialog"
      :close-on-click-modal="false"
      :visible.sync="unPublishedVisible"
    >
      <check-bidd-from :bidd="biddFrom" :downLoad="2"></check-bidd-from>
    </el-dialog>
    <el-dialog
      width="1200px"
      :center="true"
      title="发布招标书"
      :before-close="closeDialog"
      :close-on-click-modal="false"
      :visible.sync="biddVisible"
    >
      <h1>基本信息</h1>
      <el-form class="commonFrom" label-width="110px">
        <el-form-item label="招标编号：" style="margin-right: 400px">
          <el-input style="width: 280px" size="small" placeholder="请输入招标编号" v-model.trim="biddFrom.biddingNo">
          </el-input>
        </el-form-item>
        <el-form-item label="招标单位：">
          {{ biddFrom.biddingEnterprise }}
        </el-form-item>
        <el-form-item label="关联工程：" class="associate">
          <el-select size="small" v-model.trim="biddFrom.proId" placeholder="请选择工程" @change="projectChange">
            <el-option v-for="item in projetOptions" :key="item.id" :label="item.proName" :value="item.id"> </el-option>
          </el-select>
          <span style="margin-left: 10px; color: #fa7355; cursor: pointer" @click="detilProject">查看详情</span>
        </el-form-item>

        <el-form-item label="招标类型：">
          <el-radio-group v-model.trim="biddFrom.biddingType" @change="inviteBidTypeChange">
            <el-radio v-for="(item, index) in bidTypeOptions" :key="index" :label="item.dictKey">{{
              item.dictValue
            }}</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="预估总价：">
          <el-input
            style="width: 180px"
            size="small"
            ref="estimateTotalPrice"
            placeholder="请输入预估总价"
            @change="decimalChange($event, 'estimateTotalPrice')"
            v-model.trim="biddFrom.estimateTotalPrice"
          >
            <p slot="suffix" style="color: #333">万元</p>
          </el-input>
        </el-form-item>
        <el-form-item style="width: 100% !important" label="交付地点：">
          <el-select
            style="width: 150px"
            size="small"
            v-model.trim="biddFrom.provinceId"
            placeholder="请选择省"
            @change="provinceChange"
          >
            <el-option
              v-for="item in provinceOptions"
              :key="item.provinceId"
              :label="item.province"
              :value="item.provinceId"
            >
            </el-option>
          </el-select>
          <el-select
            style="width: 150px; margin-left: 10px"
            size="small"
            v-model.trim="biddFrom.cityId"
            placeholder="请选择市"
            @change="cityChange"
          >
            <el-option v-for="item in cityOptions" :key="item.cityId" :label="item.city" :value="item.cityId">
            </el-option>
          </el-select>
          <el-select
            style="width: 150px; margin-left: 10px"
            size="small"
            v-model.trim="biddFrom.areaId"
            placeholder="请选择区"
            @change="areaChange"
          >
            <el-option v-for="item in areaOptions" :key="item.areaId" :label="item.area" :value="item.areaId">
            </el-option>
          </el-select>
          <el-input
            style="width: 280px; margin-left: 10px"
            size="small"
            placeholder="请填写详细地址"
            v-model.trim="biddFrom.detailAddress"
          >
          </el-input>
        </el-form-item>
        <el-form-item label="投标截止时间：">
          <el-date-picker
            size="small"
            style="width: 280px"
            v-model.trim="biddFrom.bidDateline"
            type="datetime"
            :picker-options="pickerOptions0"
            value-format="yyyy-MM-dd HH:mm:ss"
            placeholder="选择日期"
          >
          </el-date-picker>
        </el-form-item>
        <el-form-item label="期望收货日期: " style="margin-left: 127px">
          <el-date-picker
            size="small"
            style="width: 280px"
            :picker-options="pickerOptions0"
            v-model.trim="biddFrom.expectTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="选择日期"
          >
          </el-date-picker>
        </el-form-item>
        <el-form-item label="招标内容：">
          <el-button size="small" @click="selectMaterial" type="primary" class="commonBtn1" icon="iconfont icon-add"
            >添加新品类</el-button
          >
        </el-form-item>
        <el-form-item label="" style="width: 100% !important">
          <div class="material_list" v-for="(item, index) in biddFrom.addBiddingContentDtoList" :key="index">
            {{ item.materialName }}
            <i @click="removeMaterial(index)" class="iconfont icon-guanbi"></i>
          </div>
        </el-form-item>
      </el-form>
      <h1>
        总采购清单
        <span>（未填写规格型号以及采购数量的清单不会保存）</span>
      </h1>
      <div class="inventory_btn_box">
        <div>
          <el-button size="small" type="primary" class="commonBtn1" icon="iconfont icon-add" @click="addTableIndex"
            >添加一行</el-button
          >
          <el-button size="small" class="commonBtn" @click="removeAll">清空清单</el-button>
        </div>
        <div class="right">
          <el-button size="small" class="commonBtn" @click="excelExport">导出采购清单</el-button>
          <el-button size="small" class="commonBtn" @click="importClick">导入采购清单</el-button>
          <div class="upload-wrap">
            <el-upload
              key="excel"
              :multiple="false"
              :action="excelUpload"
              :show-file-list="false"
              :headers="loadHeader"
              :on-error="excelErr"
              :on-success="excelImportSuccess"
              :data="materialObj"
              :before-upload="excelBeforeUpload"
              accept=".xls,.xlsx"
            >
              <template slot="trigger">
                <div ref="excelImport"></div>
              </template>
            </el-upload>
          </div>
        </div>
      </div>
      <el-table
        :data="biddFrom.addBiddingPurchaseListDtoList"
        border
        class="inventory_table"
        ref="jdjgTable"
        :header-cell-style="{ padding: '0px', background: '#F2F3F7' }"
        :row-class-name="tabRowClassName"
      >
        <el-table-column width="60" align="center" type="index" label="序号">
          <template slot-scope="scope">
            {{ scope.$index + 1 }}
          </template>
        </el-table-column>
        <el-table-column label="品类" align="center" prop="materialId">
          <template slot-scope="scope">
            <el-select
              v-model.trim="scope.row.materialId"
              placeholder="请选择"
              @change="typeChange($event, scope.$index)"
            >
              <el-option
                v-for="item in biddFrom.addBiddingContentDtoList"
                :label="item.materialName"
                :value="item.materialId"
                :key="item.materialId"
              ></el-option>
            </el-select>
          </template>
        </el-table-column>
        <el-table-column label="规格型号" align="center" prop="model">
          <template slot-scope="scope">
            <el-select
              v-model.trim="scope.row.model"
              placeholder="请选择"
              @change="categoryChange"
              @visible-change="selectFocus($event, scope.row.materialId)"
            >
              <el-option
                v-for="item in scope.row.modelSelectList"
                :label="item.specsName"
                :value="item.specsName"
                :key="item.id"
              ></el-option>
            </el-select>
          </template>
        </el-table-column>
        <el-table-column label="单位" align="center" prop="company"> </el-table-column>
        <el-table-column label="参数指标" align="center" prop="parameterIndex">
          <template slot-scope="scope">
            <el-input v-model.trim="scope.row.parameterIndex" placeholder="请输入参数指标"></el-input>
          </template>
        </el-table-column>
        <el-table-column label="品牌产地" align="center" prop="brandOrigin">
          <template slot-scope="scope">
            <el-input v-model.trim="scope.row.brandOrigin" placeholder="请输入品牌产地"></el-input>
          </template>
        </el-table-column>
        <el-table-column label="采购数量" align="center" prop="purchaseQuantity">
          <template slot-scope="scope">
            <el-input
              v-model.trim="scope.row.purchaseQuantity"
              placeholder="请输入采购数量"
              ref="purchaseQuantity"
              @input="purchaseQuantityChange($event, scope.$index, 'purchaseQuantity')"
            ></el-input>
          </template>
        </el-table-column>
        <el-table-column label="操作" align="center" width="80px">
          <template slot-scope="scope">
            <el-button type="text" class="ty czBtn" @click="delTableItem(scope.$index)"> 删除 </el-button>
          </template>
        </el-table-column>
      </el-table>
      <h1>付款约定</h1>
      <el-input
        type="textarea"
        :autosize="{ minRows: 3 }"
        placeholder="请输入付款约定"
        v-model.trim="biddFrom.payAgree"
      >
      </el-input>
      <h1>补充说明</h1>
      <el-input
        type="textarea"
        :autosize="{ minRows: 3 }"
        placeholder="请输入补充说明"
        v-model.trim="biddFrom.supplyNote"
      >
      </el-input>
      <h1>招标发布说明<span>（该说明不对外公开，仅企业内部员工可见）</span></h1>
      <el-input
        type="textarea"
        :autosize="{ minRows: 3 }"
        placeholder="请输入发布说明"
        v-model.trim="biddFrom.biddingReleaseNote"
      >
      </el-input>
      <h1>发票及税金</h1>
      <el-form class="commonFrom" label-width="110px">
        <el-form-item label="报价要求：">
          <el-radio
            v-for="(item, index) in quoteOptions"
            :key="index"
            v-model.trim="biddFrom.quoteAsk"
            :label="item.dictKey"
            >{{ item.dictValue }}</el-radio
          >
        </el-form-item>
        <el-form-item style="width: 60% !important" label="发票要求：">
          <el-radio
            v-for="(item, index) in invoiceOptions"
            :key="index"
            v-model.trim="biddFrom.billAsk"
            :label="item.dictKey"
            >{{ item.dictValue }}</el-radio
          >
        </el-form-item>
        <el-form-item label="投标保证金：">
          <el-input
            style="width: 180px"
            size="small"
            ref="bidBond"
            placeholder="请输入金额"
            v-model.trim="biddFrom.bidBond"
            @change="decimalChange($event, 'bidBond')"
          >
            <p slot="suffix" style="color: #333">万元</p>
          </el-input>
        </el-form-item>
        <el-form-item style="width: 60% !important" label="履约保证金：">
          <el-input
            style="width: 180px"
            size="small"
            ref="performanceBond"
            placeholder="请输入金额"
            v-model.trim="biddFrom.performanceBond"
            @change="decimalChange($event, 'performanceBond')"
          >
            <p slot="suffix" style="color: #333">万元</p>
          </el-input>
          <p class="performance_text">投标需缴纳保证金，流标后自动返还，中标可转换为履约保证金。</p>
        </el-form-item>
      </el-form>
      <h1>联系方式</h1>
      <el-form class="commonFrom" label-width="110px">
        <el-form-item label="招标联系人：">
          <el-input
            style="width: 220px"
            class="no_border"
            disabled
            size="small"
            placeholder="请选择招标联系人"
            v-model.trim="biddFrom.contactName"
          >
            <el-button @click="personnelSelect('contact', '')" slot="append">选择</el-button>
          </el-input>
        </el-form-item>
        <el-form-item label="招标联系电话：">
          {{ biddFrom.contactPhone ? biddFrom.contactPhone : '--' }}
        </el-form-item>
        <el-form-item label="技术联系人：">
          <el-input
            style="width: 220px"
            class="no_border"
            disabled
            size="small"
            placeholder="请选择技术联系人"
            v-model.trim="biddFrom.technologyName"
          >
            <el-button @click="personnelSelect('technology', '')" slot="append">选择</el-button>
          </el-input>
        </el-form-item>
        <el-form-item label="技术联系电话：">
          {{ biddFrom.technologyPhone ? biddFrom.technologyPhone : '--' }}
        </el-form-item>
      </el-form>
      <h1>
        审核人员
        <span>（未选择的审核人员不会保存）</span>
      </h1>
      <el-button size="small" type="primary" class="commonBtn1 mgn" icon="iconfont icon-add" @click="addReviewer"
        >添加审核人员</el-button
      >
      <el-form class="commonFrom auditfrom" label-width="110px">
        <el-form-item v-for="(item, index) in reviewerList" :key="index" :label="'审核人员' + (index + 1) + '：'">
          <el-input
            style="width: 220px"
            class="no_border"
            disabled
            size="small"
            placeholder="请选择审核人员"
            v-model.trim="item.reviewName"
          >
            <el-button @click="personnelSelect('reviewer', index)" slot="append">选择</el-button>
          </el-input>
          <i class="iconfont icon-guanbianniu" @click="colseReviewer(index)"></i>
        </el-form-item>
      </el-form>
      <h1>招标文件上传 <span>（单个文件需要限制在50M以内）</span></h1>
      <!-- <el-button size="small" class="commonBtn mgn">文件模版下载</el-button> -->
      <el-button size="small" type="primary" class="commonBtn1" @click="uploadClick" style="margin-top: 20px">
        上传附件
      </el-button>

      <div class="upload-wrap">
        <el-upload
          class="upload-demo"
          :headers="loadHeader"
          multiple
          accept=".doc,.docx,.pdf"
          :action="urlUpload"
          :on-remove="fileRemove"
          :on-success="uploadSuccess"
          :before-upload="beforeUpload"
          :on-exceed="onExceed"
          :file-list="fileList"
        >
          <template slot="trigger">
            <div ref="biddUpload"></div>
          </template>
        </el-upload>
      </div>

      <h1 class="mgn">推送邀标短信</h1>
      <el-radio-group class="mgn" v-model.trim="msgRadio">
        <el-radio :label="1" :disabled="biddFrom.biddingType"> 推送短信设置 </el-radio>
        <el-radio :label="2">定向推送设置</el-radio>
        <el-radio :label="3" :disabled="biddFrom.biddingType"> 不推送邀标短信 </el-radio>
      </el-radio-group>
      <div class="mgn" v-if="msgRadio == 1">
        <label for="">推送单位数量：</label>
        <el-input style="width: 220px" size="small" placeholder="请输入推送单位数量" v-model.trim="biddFrom.smsNum">
        </el-input>
        <span style="color: #fa7355; cursor: pointer" @click="checkSupplier">（查看符合推送的供应商）</span>
      </div>
      <div class="mgn" v-if="msgRadio == 2">
        <el-button size="small" class="commonBtn1" icon="iconfont icon-add" @click="addSupplier">添加推送</el-button>
        <div class="supplier-wrap">
          <div v-for="(item, index) in biddFrom.smsPublicInfoList" :key="item.id" class="supplierlist">
            <span>{{ item.enterpriseName }}</span>
            <i class="iconfont icon-guanbi" @click="delSupplier(index)"></i>
          </div>
        </div>
      </div>

      <div class="footer">
        <el-button size="small" class="commonBtn" @click="closeBtn">取消</el-button>
        <el-button size="small" class="commonBtn" @click="saveBtn">保存</el-button>
        <el-button size="small" class="commonBtn1" @click="subBtn">确定</el-button>
      </div>
    </el-dialog>
    <el-dialog
      width="765px"
      :center="true"
      title="选择联系人"
      :close-on-click-modal="false"
      :visible.sync="personVisible"
      v-if="personVisible"
    >
      <personnel-select :type="personType" :index="reviewerIndex" @close="personClose"></personnel-select>
    </el-dialog>
    <el-dialog
      width="553px"
      :center="true"
      title="工程详情"
      class="pro_dialog"
      :close-on-click-modal="false"
      :visible.sync="projectVisible"
      v-if="projectVisible"
    >
      <el-form label-width="80px">
        <el-form-item label="工程编号: "> {{ projectFrom.proNo }}</el-form-item>
        <el-form-item label="工程名称: ">
          {{ projectFrom.proName }}
        </el-form-item>
        <el-form-item label="建设单位: ">
          {{ projectFrom.developmentUnit }}
        </el-form-item>
        <el-form-item label="施工单位: ">
          {{ projectFrom.constructUnit }}
        </el-form-item>
        <el-form-item label="监理单位: ">
          {{ projectFrom.constructControlUnit }}
        </el-form-item>
        <el-form-item label="勘察单位: ">
          {{ projectFrom.surveyUnit }}
        </el-form-item>
        <el-form-item label="设计单位: ">
          {{ projectFrom.designUnit }}
        </el-form-item>
      </el-form>
    </el-dialog>
    <el-dialog
      class="dialog_detail"
      :center="true"
      :close-on-click-modal="false"
      width="1200px"
      title="选择新品类"
      :visible.sync="materialVisible"
      v-if="materialVisible"
    >
      <tertiary-material :list="biddFrom.addBiddingContentDtoList" @close="materialClose"> </tertiary-material>
    </el-dialog>
    <el-dialog
      class="dialog_detail"
      :center="true"
      :close-on-click-modal="false"
      width="1200px"
      title="选择供应商"
      :visible.sync="supplierVisiable"
      v-if="supplierVisiable"
    >
      <supplier-table
        @close="supplierClose"
        :list="biddFrom.smsPublicInfoList"
        :smsNum="biddFrom.smsNum"
        :btnshow="btnShow"
      ></supplier-table>
    </el-dialog>
  </div>
</template>
<script>
import personnelSelect from '../../../components/PersonnelSelect'
import tertiaryMaterial from '../../../components/TertiaryMaterial'
import checkBiddFrom from './components/checkBiddFrom.vue'
import FlowMarkTable from './flowmark/flowMarkTable.vue'
import PublishingTable from './publishing/publishingTable.vue'
import ShortlistTable from './shortlisted/shortlistTable.vue'
import SupplierTable from './supplierTable.vue'
import unPublishTable from './unPublished/unPublishTable.vue'
import WinningBidTable from './winningbid/winningBidTable.vue'
export default {
  data() {
    return {
      fileSuccess: true,
      num: 0,
      btnShow: true,
      pickerOptions0: {
        disabledDate(time) {
          return time.getTime() < Date.now()
        }
      },
      materialObj: {},
      projectFrom: {},
      projectVisible: false,
      supplierVisiable: false,
      urlUpload: this.GLOBAL.weburl + '/api/file/upload',
      excelUpload: this.GLOBAL.weburl + '/excel/import',
      fileList: [],
      // modelSelectList: [],
      biddTypes: [
        {
          value: '1',
          label: '未发布'
        },
        {
          value: '2',
          label: '正在发布'
        },
        {
          value: '3',
          label: '已入围·议价'
        },
        {
          value: '4',
          label: '中标'
        },
        {
          value: '5',
          label: '流标'
        }
      ],
      biddTypeValue: '1',

      PositionNameSort: null,
      unPublishedVisible: false,
      biddVisible: false,
      biddFrom: {},
      bidTypeOptions: [
        {
          dictValue: '公开',
          dictKey: false
        },
        {
          dictValue: '定向',
          dictKey: true
        }
      ],
      provinceOptions: [],
      quoteOptions: [
        {
          dictValue: '含税',
          dictKey: false
        },
        {
          dictValue: '不含税',
          dictKey: true
        }
      ],
      invoiceOptions: [
        {
          dictValue: '增值税专用发票',
          dictKey: 0
        },
        {
          dictValue: '增值税普通发票',
          dictKey: 1
        },
        {
          dictValue: '增值税电子发票',
          dictKey: 2
        }
      ],
      projetOptions: [],
      cityOptions: [],
      areaOptions: [],
      personVisible: false,
      personType: '',
      reviewerIndex: '',
      reviewerList: [
        {
          reviewName: '',
          userId: ''
        }
      ],
      timer: null,
      msgRadio: 1,
      materialVisible: false
    }
  },
  computed: {
    loadHeader() {
      let token = this.common.getCookie('materialsToken')
      const header = {}
      header[this.GLOBAL.tokenName] = token
      return header
    }
  },
  components: {
    personnelSelect,
    tertiaryMaterial,
    unPublishTable,
    SupplierTable,
    checkBiddFrom,
    PublishingTable,
    ShortlistTable,
    FlowMarkTable,
    WinningBidTable
  },
  methods: {
    // 删除文件
    fileRemove(file, files) {
      this.fileList = files
      this.num = this.fileList.length
    },
    // 再投标点击时
    reTender(scope) {
      this.fileList = []
      this.getProjectList()
      this.$https({
        method: 'post',
        url: '/purchaseAdmin/biddingInfoById/?id=' + scope.id
      })
        .then(res => {
          if (res.code === 0) {
            this.getSelect()
            // 获取市列表
            this.provinceChange(res.data.provinceId)
            // 设置区列表
            this.cityChange(res.data.cityId)
            // 获取到的数据填入内容
            this.biddFrom = res.data
            this.biddVisible = true
            res.data.biddingFile.forEach(item => {
              this.fileList.push({
                name: item.fileName,
                url: item.fileAddress
              })
            })
            this.biddFrom.biddingFile = []
            if (this.fileList.length) {
              this.num = this.fileList.length
            }
            this.msgRadio = res.data.smsType
            // 设置投标截止时间为空
            this.biddFrom.bidDateline = ''
            // 设置期望收货时间为空
            this.biddFrom.expectTime = ''
            // 设置招标id为null
            this.biddFrom.id = null
            // 设置状态
            this.biddFrom.processSon = 0
            this.biddFrom.biddingNo = null
            this.reviewerList = res.data.addReviewerDtoList
            // 保存时未填写工程id，后端会返回null，页面上会把null展示出来
            if (this.biddFrom.proId === null) {
              this.biddFrom.proId = ''
            }
            this.biddFrom.addBiddingPurchaseListDtoList.forEach(item => {
              this.$set(item, 'model', item.model + '')
            })
          } else {
            this.$message.error(res.msg)
          }
        })
        .catch(err => {
          console.log(err)
        })
    },
    closeDialog(done) {
      done()
      this.fileList = []
      this.biddFrom = {}
    },
    // 查看满足条件的供应商
    checkSupplier() {
      if (this.biddFrom.smsNum) {
        const reg = /^\+?[1-9]\d*$/
        if (!reg.test(this.biddFrom.smsNum)) {
          this.$message.error('请输入大于0的推送供应商数量')
          this.biddFrom.smsNum = ''
          return false
        }
        this.btnShow = false
        this.supplierVisiable = true
      } else {
        this.$message.error('请输入推送供应商数量')
      }
    },
    // 关联工程改变时
    projectChange(val) {
      this.projetOptions.forEach(item => {
        if (item.id === val) {
          this.biddFrom.proName = item.proName
        }
      })
    },
    // 子组件触发弹窗打开
    openBiddVisible(data) {
      if (data.tip === '编辑') {
        this.fileList = []
        this.getProjectList()
        this.$https({
          method: 'post',
          url: '/purchaseAdmin/biddingInfoById/?id=' + data.id
        })
          .then(res => {
            if (res.code === 0) {
              // 获取市列表
              this.provinceChange(res.data.provinceId)
              // 设置区列表
              this.cityChange(res.data.cityId)
              // 获取到的数据填入内容
              this.biddFrom = res.data
              this.biddVisible = true
              res.data.biddingFile.forEach(item => {
                this.fileList.push({
                  name: item.fileName,
                  url: item.fileAddress
                })
              })
              this.biddFrom.biddingFile = []
              if (this.fileList.length) {
                this.num = this.fileList.length
              }
              this.msgRadio = res.data.smsType
              this.reviewerList = res.data.addReviewerDtoList
              // 保存时未填写工程id，后端会返回null，页面上会把null展示出来
              this.biddFrom.proId = this.biddFrom.proId || ''
              this.biddFrom.addBiddingPurchaseListDtoList.forEach(item => {
                this.$set(item, 'model', item.model + '')
              })
            } else {
              this.$message.error(res.msg)
            }
          })
          .catch(err => {
            console.log(err)
          })
      } else if (data.tip === '查看') {
        this.$https({
          method: 'post',
          url: '/purchaseAdmin/biddingInfoById/?id=' + data.id
        }).then(res => {
          if (res.code === 0) {
            this.biddFrom = res.data
            this.unPublishedVisible = true
          } else {
            this.$message.error(res.msg)
          }
        })
      }
    },
    // 删除供应商
    delSupplier(index) {
      this.biddFrom.smsPublicInfoList.splice(index, 1)
    },
    supplierClose(val) {
      this.supplierVisiable = false
      if (val) {
        let arr = []
        val.forEach(item => {
          arr.push({
            enterpriseId: item.id,
            phone: item.phone,
            enterpriseName: item.enterpriseName
          })
        })
        this.biddFrom.smsPublicInfoList = this.biddFrom.smsPublicInfoList.concat(arr)
      }
    },
    // 添加供应商
    addSupplier() {
      this.btnShow = true
      this.biddFrom.smsNum = null
      this.supplierVisiable = true
    },
    // 文件上传前进行文件大小检测
    beforeUpload(file) {
      this.fileSuccess = false
      const isLt = file.size / 1024 / 1024 / 50 <= 1
      if (!isLt) {
        this.$message.error('单个文件大小不能超过50M,请检查文件大小并重新尝试')
      }
      return isLt
    },
    // 文件上传前判断是否超过同时上传文件个数限制
    onExceed() {
      this.$message.error('最多支持同时上传3个文件，请重新上传')
    },
    // 上传成功时的回调
    uploadSuccess(val, e, el) {
      this.num++
      if (this.num == el.length) {
        this.num = el.length
        this.fileSuccess = true
      }
      clearTimeout(this.timer)
      this.timer = setTimeout(() => {
        this.$message.success('上传成功')
      }, 200)

      this.fileList = el
    },
    // 触发上传
    uploadClick() {
      this.$refs.biddUpload.click()
    },
    decimalChange(val, refName) {
      if (val) {
        if (!this.common.fieldTest('decimal', val)) {
          this.$refs[refName].clear()
          this.$message.error('你输入的数字格式有误或太小，最多输入小数点后4位')
        }
      }
    },
    downloadFile(res, filename) {
      var a = document.createElement('a')
      // var blob = new Blob([res], {
      //   type: filename.split('.')[1]
      // })
      // this.dataURLtoBlob
      var blob = this.dataURLtoBlob(res, filename)
      var url = window.URL.createObjectURL(blob)
      a.href = url
      a.download = filename
      a.click()
      window.URL.revokeObjectURL(url)
    },

    dataURLtoBlob(base64Str, filename) {
      var bstr = atob(base64Str),
        n = bstr.length,
        u8arr = new Uint8Array(n)
      while (n--) {
        u8arr[n] = bstr.charCodeAt(n)
      }
      // 下载的是excel格式的文件
      return new Blob([u8arr], { type: filename.split('.')[1] })
    },
    // 导入采购清单
    importClick() {
      this.$refs.excelImport.click()
    },
    // 成功时
    excelImportSuccess(res) {
      if (res.code === 0) {
        this.biddFrom.addBiddingPurchaseListDtoList = res.data.slice(0, 20)
        this.$message.success(res.msg)
      } else {
        this.$message.error(res.msg)
      }
    },
    // 失败时
    excelErr(err) {
      console.log(err)
    },
    excelBeforeUpload(file) {
      let arr = []
      let hz = file.name.substring(file.name.lastIndexOf('.') + 1)
      const isExcel = hz === 'xlsx' || hz === 'xls'
      if (!isExcel) {
        this.$message.error(`只能选择excel文件`)
        return false
      }
      // 导入时判断是否选择了品类
      if (!this.biddFrom.addBiddingContentDtoList.length) {
        this.$message.error('请先选择品类才能导入文件')
        return false
      }
      // 判断文件大小
      let fileSize = file.size / 1024 / 1024 < 5
      if (!fileSize) {
        this.$message.error('上传文件大小不能超过 5MB')
        return false
      }
      this.biddFrom.addBiddingContentDtoList.forEach(item => {
        arr.push(item.materialId)
      })
      this.$set(this.materialObj, 'ids', arr.join(','))
      return isExcel && fileSize && this.biddFrom.addBiddingContentDtoList.length
    },

    // 导出采购清单
    excelExport() {
      let ids = []
      let arr = this.biddFrom.addBiddingContentDtoList.filter(item => {
        return item.materialId
      })
      if (!arr.length) {
        this.$message.error('请先选择品类')
        return false
      }
      arr.forEach(item => {
        ids.push(item.materialId)
      })
      this.$https({
        method: 'get',
        url: '/excel/export?ids=' + ids.join(',')
      })
        .then(res => {
          if (res.code === 0) {
            this.downloadFile(res.data, '采购清单.xls')
          } else {
            this.$message.error(res.msg)
          }
        })
        .catch(err => {
          console.log(err)
        })
    },
    // 清空采购清单
    removeAll() {
      this.$confirm('是否清空采购清单?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(() => {
          this.biddFrom.addBiddingPurchaseListDtoList = []
        })
        .catch(() => {
          this.$message('已取消')
        })
    },
    // 删除采购清单的一项
    delTableItem(index) {
      this.biddFrom.addBiddingPurchaseListDtoList.splice(index, 1)
    },
    // 品类改变时清空规格型号以及单位
    typeChange(e, index) {
      this.biddFrom.addBiddingContentDtoList.forEach(item => {
        if (item.materialId === e) {
          this.$set(this.biddFrom.addBiddingPurchaseListDtoList[index], 'materialName', item.materialName)
        }
      })
      this.$set(this.biddFrom.addBiddingPurchaseListDtoList[index], 'model', '')
      this.$set(this.biddFrom.addBiddingPurchaseListDtoList[index], 'company', '')
    },
    // 规格型号改变时设置单位
    categoryChange(val) {
      this.biddFrom.addBiddingPurchaseListDtoList.forEach(element => {
        if (val === element.model) {
          element.modelSelectList.forEach(el => {
            if (el.specsName === val) {
              this.$set(element, 'company', el.materialUnit)
            }
          })
        }
      })
    },
    selectFocus(e, id) {
      // 根据材料id获取规格型号
      if (e) {
        if (id) {
          this.$https({
            url: '/material/listMaterialSpecsByMaterialId/?materialId=' + +id,
            method: 'post'
          })
            .then(res => {
              if (res.code === 0) {
                this.biddFrom.addBiddingPurchaseListDtoList.forEach(element => {
                  if (id === element.materialId) {
                    this.$set(element, 'modelSelectList', res.data)
                  }
                })
              } else {
                this.$message.error(res.msg)
              }
            })
            .catch(err => {
              console.log(err)
            })
        } else {
          this.$message.error('请选择材料名称')
        }
      }
    },
    // 添加一行表格数据
    addTableIndex() {
      if (this.biddFrom.addBiddingPurchaseListDtoList.length >= 20) {
        this.$message.error('最多设置二十条采购材料')
      } else {
        this.biddFrom.addBiddingPurchaseListDtoList.push({
          purchaseQuantity: '',
          brandOrigin: '',
          parameterIndex: '',
          company: '',
          model: '',
          modelSelectList: '',
          materialId: '',
          materialName: ''
        })
      }
    },
    purchaseQuantityChange(val, index, prop) {
      if (val) {
        if (!this.common.fieldTest('count', val)) {
          this.biddFrom.addBiddingPurchaseListDtoList[index][prop] = null
          this.$message.error('你输入的采购数量格式有误或超出范围,请重新输入')
        }
      }
    },
    // 招标类型单选按钮改变时触发
    inviteBidTypeChange(e) {
      if (e) {
        this.msgRadio = 2
      }
    },
    //选择人员弹窗关闭
    personClose(e) {
      if (this.personType == 'contact') {
        this.biddFrom.contactName = e.userName
        this.biddFrom.contactPhone = e.phone
        this.biddFrom.contactNameId = e.id
      } else if (this.personType == 'technology') {
        this.biddFrom.technologyName = e.userName
        this.biddFrom.technologyPhone = e.phone
        this.biddFrom.technologyNameId = e.id
      } else {
        this.reviewerList[this.reviewerIndex].reviewName = e.userName
        this.reviewerList[this.reviewerIndex].userId = e.id
      }

      this.personVisible = false
    },
    //添加审核人
    addReviewer() {
      if (this.reviewerList.length < 5) {
        this.reviewerList.push({
          reviewName: '',
          userId: ''
        })
      } else {
        this.$message.error('最多添加5位审核人员')
      }
    },
    //删除审核人
    colseReviewer(index) {
      if (this.reviewerList.length > 1) {
        this.$confirm('是否删除审核人?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        })
          .then(() => {
            this.$message({
              type: 'success',
              message: '删除成功!'
            })
            this.reviewerList.splice(index, 1)
          })
          .catch(() => {})
      } else {
        this.$message.error('审核人不能少于一个')
      }
    },
    //选择联系人
    personnelSelect(type, index) {
      this.reviewerIndex = index
      this.personVisible = true
      this.personType = type
    },
    //tab切换
    handleClick(tab, event) {
      this.pageSize = 1
      this.getData()
    },
    //获取表格数据
    getData() {},
    //关闭弹窗事件
    handleClose() {},
    //获取省份
    getSelect() {
      this.common.getAddressList('province').then(value => {
        this.provinceOptions = value
      })
    },
    //选完省后获取市
    provinceChange(e) {
      this.biddFrom.city = ''
      this.biddFrom.cityId = ''
      this.biddFrom.area = ''
      this.biddFrom.areaId = ''
      this.provinceOptions.forEach(item => {
        if (e == item.provinceId) {
          this.biddFrom.province = item.province
        }
      })

      this.common.getAddressList('city', e).then(value => {
        this.cityOptions = value
      })
    },
    //选完市后获取区
    cityChange(e) {
      this.biddFrom.area = ''
      this.biddFrom.areaId = ''
      this.cityOptions.forEach(item => {
        if (e == item.cityId) {
          this.biddFrom.city = item.city
        }
      })
      this.common.getAddressList('area', e).then(value => {
        this.areaOptions = value
      })
    },
    // 选择区时设置区名
    areaChange(e) {
      this.areaOptions.forEach(item => {
        if (e == item.areaId) {
          this.biddFrom.area = item.area
        }
      })
    },
    //发布招标书--打开弹窗
    publishBtn() {
      this.fileList = []
      this.province = ''
      this.city = ''
      this.num = 0
      this.biddFrom = {
        biddingEnterprise: localStorage.getItem('enterpriseName'),
        biddingEnterpriseId: parseInt(localStorage.getItem('enterpriseId')),
        biddingType: false,
        province: '',
        provinceId: null,
        city: '',
        cityId: null,
        biddingNo: '',
        area: '',
        areaId: null,
        estimateTotalPrice: '',
        detailAddress: '',
        bidDateline: '',
        expectTime: '',
        proId: '',
        proName: '',
        payAgree: '',
        supplyNote: '',
        biddingReleaseNote: '',
        quoteAsk: false,
        billAsk: 0,
        bidBond: '',
        smsNum: null,
        id: null,
        processSon: 0,
        biddingFile: [],
        performanceBond: '',
        contactNameId: '',
        contactName: '',
        contactPhone: '',
        technologyNameId: '',
        technologyName: '',
        technologyPhone: '',
        smsType: 0,
        smsPublicInfoList: [],
        addReviewerDtoList: [],
        addBiddingContentDtoList: [],
        addBiddingPurchaseListDtoList: []
      }
      this.fileSuccess = true
      this.msgRadio = 1
      this.reviewerList = [
        {
          reviewName: '',
          userId: ''
        }
      ]
      this.biddVisible = true
      // 打开发布招标书弹窗后获取工程下拉
      this.getProjectList()
    },
    // 查看工程详情
    detilProject() {
      this.projectFrom = {}
      if (this.biddFrom.proId) {
        this.projetOptions.forEach(item => {
          if (item.id === this.biddFrom.proId) {
            this.projectFrom = item
          }
        })
        this.projectVisible = true
      } else {
        this.$message.error('请选择工程')
      }
    },
    // 获取工程下拉
    getProjectList() {
      this.$https({
        method: 'post',
        url: '/purchaseAdmin/listProjectById',
        data: {}
      })
        .then(res => {
          if (res.code === 0) {
            this.projetOptions = res.data
          } else {
            this.$message.error(res.msg)
          }
        })
        .catch(err => {
          console.log(err)
        })
    },
    //关闭发布招标书
    closeBtn() {
      this.fileList = []
      this.biddVisible = false
    },
    //发布招标书 暂存按钮
    saveBtn() {
      this.biddFrom.addReviewerDtoList = this.reviewerList
      this.biddFrom.smsType = this.msgRadio

      this.biddFrom.addReviewerDtoList.forEach((item, index) => {
        this.$set(item, 'reviewOrder', index)
      })

      if (!this.fileSuccess) {
        this.$message.error('请等待文件上传完毕')
        return false
      } else {
        if (this.fileList.length) {
          this.fileList.forEach(item => {
            if (item.url) {
              this.biddFrom.biddingFile.push({
                fileAddress: item.url,
                fileName: item.name
              })
            } else {
              this.biddFrom.biddingFile.push({
                fileAddress: item.response.data,
                fileName: item.name
              })
            }
          })
        } else {
          this.biddFrom.biddingFile = []
        }
      }
      if (this.biddFrom.smsNum) {
        const reg = /^\+?[1-9]\d*$/
        if (!reg.test(this.biddFrom.smsNum)) {
          this.$message.error('请输入大于0的推送供应商数量')
          this.biddFrom.smsNum = ''
          return false
        }
      }

      this.saveBidd()
    },
    //发布招标书 确定按钮
    subBtn() {
      let arr = this.biddFrom.addBiddingPurchaseListDtoList.filter(item => {
        return item.model && item.purchaseQuantity
      })
      this.biddFrom.addReviewerDtoList = this.reviewerList.filter(item => {
        return item.userId != ''
      })

      if (!this.fileSuccess) {
        this.$message.error('请等待文件上传完毕')
        return false
      } else {
        this.biddFrom.biddingFile = []
        if (this.fileList.length) {
          this.fileList.forEach(item => {
            if (item.url) {
              this.biddFrom.biddingFile.push({
                fileAddress: item.url,
                fileName: item.name
              })
            } else {
              this.biddFrom.biddingFile.push({
                fileAddress: item.response.data,
                fileName: item.name
              })
            }
          })
        }
      }

      if (!this.biddFrom.biddingNo) {
        this.$message.error('招标编号不能为空')
        return false
      } else if (!this.biddFrom.proId) {
        this.$message.error('关联工程不能为空')
        return false
      } else if (!this.biddFrom.estimateTotalPrice) {
        this.$message.error('预估总价不能为空')
        return false
      } else if (
        this.biddFrom.area == '' ||
        this.biddFrom.province == '' ||
        this.biddFrom.city == '' ||
        this.biddFrom.detailAddress == ''
      ) {
        this.$message.error('交付地址应填写完整')
        return false
      } else if (!this.biddFrom.bidDateline) {
        this.$message.error('截止日期不能为空')
        return false
      } else if (!this.biddFrom.addBiddingContentDtoList.length) {
        this.$message.error('请选择招标内容')
        return false
      } else if (!arr.length) {
        this.$message.error('请添加采购清单,未填写规格型号以及采购数量的清单不会保存')
        return false
      } else if (!this.biddFrom.bidBond) {
        this.$message.error('请输入投标保证金')
        return false
      } else if (!this.biddFrom.performanceBond) {
        this.$message.error('请输入履约保证金')
        return false
      } else if (!this.biddFrom.contactName) {
        this.$message.error('请选择招标联系人')
        return false
      } else if (!this.biddFrom.technologyName) {
        this.$message.error('请选择技术联系人')
        return false
      } else if (!this.biddFrom.addReviewerDtoList.length) {
        this.$message.error('请选择审核人')
        return false
      } else if (!this.biddFrom.biddingFile.length) {
        this.$message.error('请上传文件')
        return false
      }
      if (this.msgRadio === 1) {
        if (!this.biddFrom.smsNum) {
          this.$message.error('请输入推送单位数量')
          return false
        } else {
          const reg = /^\+?[1-9]\d*$/
          if (!reg.test(this.biddFrom.smsNum)) {
            this.$message.error('请输入大于0的推送供应商数量')
            this.biddFrom.smsNum = ''
            return false
          }
        }
      } else if (this.msgRadio === 2) {
        if (!this.biddFrom.smsPublicInfoList.length) {
          this.$message.error('请选择推送单位')
          return false
        }
      }
      let bidDateline = this.biddFrom.bidDateline.replace(/-/g, '/')
      let endDate = new Date(bidDateline).getTime()
      let nowDate = new Date(new Date(new Date().toLocaleDateString()).getTime() + 24 * 60 * 60 * 1000 - 1).getTime()
      if (endDate < nowDate) {
        this.$message.error('请选择今天以后的投标截止日期')
        this.biddFrom.bidDateline = ''
        return false
      }

      // 设置状态为提交
      this.biddFrom.processSon = 1
      this.biddFrom.addBiddingPurchaseListDtoList = arr
      // 确定时给审核人添加index
      this.biddFrom.addReviewerDtoList.forEach((item, index) => {
        this.$set(item, 'reviewOrder', index)
      })
      this.biddFrom.smsType = this.msgRadio
      this.saveBidd()
    },
    saveBidd() {
      this.$https({
        method: 'post',
        url: '/purchaseAdmin/releaseBidding',
        data: this.biddFrom
      })
        .then(res => {
          if (res.code === 0) {
            this.fileList = []
            this.$message.success('操作成功')
            this.biddVisible = false
            this.biddFrom = {}
            this.$refs.tablelist.getData()
          } else {
            this.$message.error(res.msg)
          }
        })
        .catch(err => {
          console.log(err)
        })
    },
    //选择新品类 打开弹窗
    selectMaterial() {
      this.materialVisible = true
    },
    //选择新品类 接收组件返回数据
    materialClose(e) {
      let el
      if (e.length > 0) {
        e.forEach(item => {
          if (item.dj === 3) {
            el = JSON.parse(
              JSON.stringify(e)
                .replace(/id/g, 'materialId')
                .replace(/fatherId/g, 'typeTwoId')
            )
          }
        })
        this.biddFrom.addBiddingContentDtoList = el
      } else {
        this.biddFrom.addBiddingContentDtoList = []
      }
      this.materialVisible = false
    },
    //删除已选择物资
    removeMaterial(index) {
      const materialId = this.biddFrom.addBiddingContentDtoList[index].materialId
      let bidarr = []
      this.biddFrom.addBiddingPurchaseListDtoList.forEach((item, index) => {
        if (item.materialId != materialId) {
          bidarr.push(...this.biddFrom.addBiddingPurchaseListDtoList.slice(index, index + 1))
        }
      })
      this.biddFrom.addBiddingPurchaseListDtoList = [...bidarr]
      bidarr = []
      this.biddFrom.addBiddingContentDtoList.splice(index, 1)
    },
    sortChange() {},
    addIndex(index) {
      return index + 1 + (this.size - 1) * this.page
    },
    tabRowClassName({ row, rowIndex }) {
      let index = rowIndex + 1
      if (index % 2 == 0) {
        return 'warning-row'
      }
    }
  },
  mounted() {
    this.getSelect()
  }
}
</script>

<style lang="less">
.associate {
  .el-select {
    width: 180px;
    margin: 0;
  }
  .el-form-item__content {
    width: calc(100% - 100px);
  }
}
.upload-wrap {
  // display: none;
  // display: flex;
  // .upload-demo {
  //   margin-top: 20px;
  //   margin-left: 20px;
  // }
  .el-upload {
    display: none;
  }
  .el-upload-list {
    display: flex;
    align-items: center;
    width: 600px;
    flex-wrap: wrap;
    .el-upload-list__item {
      width: 260px;
      margin: 20px 30px 0 0;
      background: #f0f1f2;
      border: 1px solid #d6d6d6;
    }
    .el-icon-close {
      &:hover {
        color: #fa7355;
      }
    }
  }
  .el-upload-list__item.is-success .el-upload-list__item-name:focus,
  .el-upload-list__item.is-success .el-upload-list__item-name:hover {
    color: #fa7355;
  }
}
</style>
<style scoped lang="less">
.pro_dialog {
  .el-form-item {
    margin-bottom: 0;
  }
}
.dashedbox {
  display: flex;
  height: 32px;
  line-height: 32px;
  border-bottom: 1px dashed #dedede;
  .mg-box {
    margin-right: 100px;
  }
}
.supplier-wrap {
  display: flex;
  flex-wrap: wrap;
  .supplierlist {
    width: 212px;
    height: 32px;
    line-height: 32px;
    padding: 0 16px;
    font-size: 14px;
    border: 1px solid #d6d6d6;
    border-radius: 5px;
    margin-right: 20px;
    margin-top: 20px;
    .icon-guanbi {
      float: right;
      cursor: pointer;
      &:hover {
        color: #fa7355;
      }
    }
  }
}
.ty {
  color: #ff3d3d;
}
.list-container {
  padding: 16px 16px 40px 16px;
  height: calc(100% - 116px);
}
.biddBtn {
  position: absolute;
  top: 15px;
  right: 15px;
  z-index: 999;
}
h1 {
  font-size: 16px;
  font-weight: 500;
  color: #333;
  padding-left: 10px;
  border-left: 4px solid #fa7355;
  span {
    font-weight: normal;
    color: #999;
    margin-left: 10px;
    text-align: left;
  }
}
.commonFrom {
  margin-top: 10px;
  width: 80%;
  .el-form-item {
    width: 40% !important;
  }
  .performance_text {
    color: #fa7355;
    font-size: 14px;
  }
  .icon-guanbianniu {
    font-size: 16px;
    cursor: pointer;
    margin-left: 10px;
  }
  .icon-guanbianniu:hover {
    color: #fa7355;
  }
}
.auditfrom {
  .el-form-item {
    width: 41% !important;
  }
}
.inventory_btn_box {
  margin-top: 20px;
  display: flex;
  justify-content: space-between;
  div {
    width: 50%;
  }
  .right {
    display: flex;
    justify-content: flex-end;
    .upload-wrap {
      display: none;
    }
  }
}
.inventory_table {
  margin: 20px 0;
  width: 100%;
}
.el-textarea {
  margin: 20px 0;
  width: 100%;
}
.mgn {
  margin-top: 20px;
}
.footer {
  .commonBtn,
  .commonBtn1 {
    width: 130px;
  }
  text-align: center;
  margin-top: 40px;
}
.material_list {
  display: inline-block;
  padding: 5px 10px;
  font-size: 14px;
  line-height: normal;
  box-sizing: border-box;
  border: 1px solid #d6d6d6;
  border-radius: 5px;
  margin: 10px 20px 10px 0;
  .iconfont {
    font-size: 12px;
    cursor: pointer;
  }
  .iconfont:hover {
    color: #fa7355;
  }
}
</style>
